package cn.cuilan.controller;

import cn.cuilan.entity.SysUser;
import cn.cuilan.service.SysUserService;
import cn.cuilan.utils.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统用户管理
 *
 * @author zhang.yan
 */
@RestController
@RequestMapping(value = "/admin/sysUser")
public class AdminSysUserController {

    private final SysUserService sysUserService;

    @Autowired
    public AdminSysUserController(SysUserService sysUserService) {
        this.sysUserService = sysUserService;
    }

    /**
     * 重置密码
     *
     * @param id       系统用户id
     * @param password 密码
     * @return 返回成功
     */
    @RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
    public Results resetPassword(@RequestParam long id, @RequestParam String password) {
        return Results.success().data("sysUser", sysUserService.resetPassword(id, password));
    }

    /**
     * 根据条件查询所有系统用户
     *
     * @param sysUser 系统用户VO对象
     * @return 返回成功
     */
    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    public Results getAllSysUser(SysUser sysUser) {
        return Results.success().data("sysUsers", sysUserService.findAllSysUser(sysUser));
    }

}
